package com.wmlive.hhvideo.heihei.personal.util;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.view.View;

/**
 * Created by XueFei on 2017/6/6.
 * <p>
 * 一行 3列 距上 距左 space距离
 */

public class SpaceItemDecoration extends RecyclerView.ItemDecoration {
    private int space;
    private boolean mIsHaveHeadView = false;//是否有headview

    public SpaceItemDecoration(int space, boolean isHaveHeadView) {
        this.space = space;
        mIsHaveHeadView = isHaveHeadView;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        if (mIsHaveHeadView) {
            if (parent.getChildAdapterPosition(view) != 0) {
                outRect.bottom = space;
                if (parent.getChildAdapterPosition(view) % 3 != 0) {
                    outRect.right = space;
                }
            }
        } else {
            outRect.bottom = space;
            if (parent.getChildAdapterPosition(view) % 3 != 0) {
                outRect.left = space;
            }
        }
    }
}
